//
//  ST_DarkCommentCell.swift
//  btvideo
//
//  Created by mac on 2020/6/8.
//  Copyright © 2020 JarvanZhang. All rights reserved.
//

import UIKit
import SnapKit
import SwifterSwift
import HandyJSON
import SwiftyAttributes

class ST_DarkCommentCell: UITableViewCell {
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
    
        self.selectionStyle = .none
        self.backgroundColor = .clear
        contentView.backgroundColor = .clear
        
        contentView.addSubview(avatar_image_view)
        avatar_image_view.snp.makeConstraints { (make) in
            make.width.height.equalTo(36)
            make.left.equalToSuperview().offset(15)
            make.top.equalToSuperview().offset(10)
        }
        
        contentView.addSubview(nickname_label)
        nickname_label.snp.makeConstraints { (make) in
            make.height.equalTo(20)
            make.left.equalToSuperview().offset(62)
            make.top.equalToSuperview().offset(10)
        }
        
        
        contentView.addSubview(time_label)
        time_label.snp.makeConstraints { (make) in
            make.height.equalTo(17)
            make.left.equalToSuperview().offset(62)
            make.top.equalTo(nickname_label.snp.bottom).offset(1)
        }
        
        contentView.addSubview(content_label)
        content_label.snp.makeConstraints { (make) in
            make.bottom.equalToSuperview().offset(-5)
            make.left.equalToSuperview().offset(62)
            make.right.equalToSuperview().offset(-15)
        }
        
        contentView.addSubview(sign_image_container)
        sign_image_container.snp.makeConstraints { (make) in
            make.left.equalTo(nickname_label.snp.right).offset(4)
            make.centerY.equalTo(nickname_label).offset(-1)
            make.height.equalTo(18)
            make.width.equalTo(70)
        }
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
//    MARK: - properties
    fileprivate lazy var avatar_image_view:UIImageView = {
       let control = UIImageView()
        control.contentMode = .scaleAspectFill
        control.cornerRadius = 36/2.0
        let tap = UITapGestureRecognizer.init(target: self, action: #selector(push_user_center_handle))
        control.isUserInteractionEnabled = true
        control.addGestureRecognizer(tap)
        return control
    }()
    
    fileprivate lazy var nickname_label:UILabel = {
        let control = UILabel.init()
        control.textColor = Color.init(hexString: "#ACB4C0")
        control.font = UIFont.systemFont(ofSize: 14, weight: UIFont.Weight.medium)
        return control
    }()
    
    fileprivate lazy var time_label:UILabel = {
        let control = UILabel.init()
        control.textColor = Color.init(hexString: "#61666F")
        control.font = UIFont.systemFont(ofSize: 12, weight: UIFont.Weight.regular)
        return control
    }()
    
    fileprivate lazy var content_label:UILabel = {
        let control = UILabel.init()
        control.numberOfLines = 0
        return control
    }()
    
    fileprivate lazy var sign_image_container:ST_UserSignView = {
        let control = ST_UserSignView()
        return control
    }()
    
    var model = ST_CommentTableCellModel(){
        didSet{
            
            
            nickname_label.text = model.nickname
            
            avatar_image_view.pin_setImage(from: model.avatar.compress_small_image(width: 37*3).url, placeholderImage: ST_SwiftConst.shared.fetch_random_place_holder_image())
            
            if model.is_anonymous == 1{
                
                sign_image_container.bind_data(isVip: false, detectedFace: false)
            }else{
                
                
                sign_image_container.bind_data(isVip: CHECK_MEMBER_STATUS(expirationTime: model.vip_expire) == .subscribe, detectedFace: model.face_audit_state == 3)
            }
            
            
            time_label.text = model.create_time.double.b_t_global_date_string()
            
            content_label.attributedText = model.commentAttr
            
            
            
            
            
            
            
        }
    }
    
    
    @objc fileprivate func push_user_center_handle(){
        
        if model.is_anonymous == 1{
            return
        }
        
        let vc = ST_PairsCenterViewController()
        
        vc.accid = self.model.accid

        let nav = PairsCenterInteractiveNavigationController.init(rootViewController: vc)
        
        nav.overCurrentContext = true
        
        GlobalPresent(toController: nav)
        
    }
}
